package com.scsj.supermarket.view.activity.bankcardmodel;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.google.gson.Gson;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.BankCardPicAdapter;
import com.scsj.supermarket.base.SelectUserHasBindBankCardBase;
import com.scsj.supermarket.bean.CommAlreadyBean;
import com.scsj.supermarket.bean.SelectUserHasBindBankCardBean;
import com.scsj.supermarket.bean.parameter.SelectUserHasBindBankCardPostBean;
import com.scsj.supermarket.presenter.SelectUserHasBindBankCardPresenter;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import es.dmoral.toasty.Toasty;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 银行卡列表
 */
public class AddBankCardPicActivity extends BaseActivity implements View.OnClickListener, SelectUserHasBindBankCardBase.IView {

    private RecyclerView bankCardListRv;

    private List<CommAlreadyBean> commAlreadyBeans;

    private BankCardPicAdapter bankCardPicAdapter;
    /**
     * 添加银行卡
     */
    private Button mAddBankCardBtn;
    private SelectUserHasBindBankCardPresenter presenter;


    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_add_bank_card_pic);
        presenter = new SelectUserHasBindBankCardPresenter(this);
        initView();
        SelectUserHasBindBankCardPostBean postBean = new SelectUserHasBindBankCardPostBean();
        postBean.setPageInfo(new SelectUserHasBindBankCardPostBean.PageInfoBean(1,20));
        String s = new Gson().toJson(postBean);
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),s);
        presenter.deliverData(body);
        initData();
        initListener();
        initToolbar();
        setToolbarTitle("添加银行卡");
        hasBack(true);

    }

    @Override
    protected void initView() {

        bankCardListRv = findViewById(R.id.bank_card_pic_rv);
        mAddBankCardBtn = (Button) findViewById(R.id.add_bank_card_btn);

    }

    @Override
    protected void initListener() {
        mAddBankCardBtn.setOnClickListener(this);
    }

    @Override
    protected void initData() {


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.add_bank_card_btn:
                SkipUtils.toAddBankCard(this);
                break;
            default:
                break;
        }
    }

    @Override
    public void showSuccessMsg(String s, SelectUserHasBindBankCardBean bean) {

        commAlreadyBeans = new ArrayList<>();
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));
        commAlreadyBeans.add(new CommAlreadyBean(R.mipmap.zzz_clothing, "交路口附近阿拉山口放假啊李开复阿萨冷风机", "获得254积分"));

        bankCardPicAdapter = new BankCardPicAdapter(bean.getData().getList());
        LinearLayoutManager layout = new LinearLayoutManager(this);
        layout.setOrientation(LinearLayoutManager.VERTICAL);
        bankCardListRv.setLayoutManager(layout);
        bankCardListRv.setAdapter(bankCardPicAdapter);
    }

    @Override
    public void showErrorMsg(String s) {
        Toasty.error(this,s).show();
    }
}
